#ifndef __GOLFDDS__
#define __GOLFDDS__

#ifdef __cplusplus
extern "C" {
#endif
typedef void *GOLFDDS_NODE_HANDLE;
typedef void *GOLFDDS_SUBSCRIBER_HANDLE;
typedef void *GOLFDDS_PUBLISHER_HANDLE;

typedef struct
{
  char nodename[64];
  char topicname[64];
} SUBSCRIBERINFO;
typedef struct
{
  char nodename[64];
  char topicname[64];
  char shmpath[256];
  int shmid;
  int msgsize;
  int queuelen;
} PUBLISHERINFO;

typedef enum {
  PUBINFO,
  SUBLIST,
} PUBSUBTYPE;
typedef struct
{ // 简单的主题列表
  int count;
  char topics[32][32];
} SUBSCRIBERLIST;
typedef struct _pubsubinfo {
  PUBSUBTYPE type;
  union {
    SUBSCRIBERINFO subinfo;
    PUBLISHERINFO pubinfo;
    SUBSCRIBERLIST list;
  };
  struct _pubsubinfo *next;
} PUBSUBINFO;

GOLFDDS_NODE_HANDLE golfdds_create_node(const char *nodename);
GOLFDDS_PUBLISHER_HANDLE golfdds_create_publisher(GOLFDDS_NODE_HANDLE node, const char *topicname, int msgsize, int queuelen);

typedef void (*GOLFDDS_MSGCALLBACK)(void *data, int len);
GOLFDDS_SUBSCRIBER_HANDLE golfdds_create_subscriber(GOLFDDS_NODE_HANDLE node, const char *topicname, GOLFDDS_MSGCALLBACK msgcallback);

void golfdds_publish(GOLFDDS_PUBLISHER_HANDLE publisher, void *message);
int golfdds_subscriber_count(GOLFDDS_PUBLISHER_HANDLE publisher);

void golfdds_spin(GOLFDDS_NODE_HANDLE handle);
void udpsend(int sockfd, void *msg, int len, char *ip, int port);
void golfdds_exit(GOLFDDS_NODE_HANDLE handle);

#ifdef __cplusplus
}
#endif
#endif